<template>
  <base-page-view class-name="details-container">
    <view v-for="(pitem, pindex) in acutlArr" :key="pindex" class="logItemOut">
      <view class="month">
        {{ getCnMonth(pindex) }}
      </view>
      <view v-for="(item, index) in pitem" :key="index" class="logItemBox">
        <view class="leftCont">
          <view class="title">
            签到成功
          </view>
          <view class="date">
            {{ _formatDate(item.createAt,'yyyy-MM-dd HH:mm:ss') }}
          </view>
        </view>
        <view class="rightCont" :class="{'isReward': item.rewardCount !== 0}">
          {{ item.rewardCount === 0 ? '+1' : '获得奖励' }}
        </view>
      </view>
    </view>
    <view v-if="list.length<1" class="empty_view">
      <b-image src="/static/images/empty/empty_coupon.png" class="img" :is-asset="true" />
      <view class="tit">暂无奖励明细~</view>
      <view class="tit titC">再接再励继续加油哦~</view>
    </view>
  </base-page-view>
</template>
<script>
import { formatDate } from '@/utils/tools'
import './index.scss'
export default {
  data() {
    return {
      list: [],
      page_index: 1,
      acutlArr: {},
      months: [
        '一月',
        '二月',
        '三月',
        '四月',
        '五月',
        '六月',
        '七月',
        '八月',
        '九月',
        '十月',
        '十一月',
        '十二月'
      ]
    }
  },
  onLoad() {
    this.getList()
  },
  methods: {
    async getList() {
      const res = await this.$api.excellentApi.signInRewardLog({
        activity_id: 2,
        page_index: this.page_index,
        page_size: 10
      })
      if (res.code || !res.data) {
        return
      }
      this.list = res.data.logs
      this._format(this.list)
    },
    _format(list) {
      const acutlArr = {}
      list.forEach(item => {
        const year = new Date(item.createAt).getFullYear()
        const month = new Date(item.createAt).getMonth() + 1
        const key = `${year}年${month}月`
        if (!acutlArr[key]) {
          acutlArr[key] = []
        }
        acutlArr[key].push(item)
      })
      this.acutlArr = acutlArr
      console.log(this.acutlArr)
    },
    _formatDate(date, type) {
      return formatDate(date, type)
    },
    getCnMonth(month) {
      const begin = month.indexOf('年')
      const end = month.indexOf('月')
      return this.months[parseInt(month.substring(begin + 1, end)) - 1]
    }
  }
}
</script>
